/*
 * Albareth - an action roleplaying game.
 * Copyright (C) 2008 Jens Anuth
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *   02110-1301, USA.
 * 
 * $Id: MenuItem.java 47 2008-05-16 21:01:33Z jens464 $
*/
package albareth.frontend.slick.ui;

import org.newdawn.slick.Color;
import org.newdawn.slick.Image;



public class MenuItem implements DraggeableItem, Cloneable
{
    private String _text;
    private Image _iconImage = null;
    private String _tooltip = null;
    private String _shortcutString = null;
    private int _id = 0;
    private Object _referencedObject = null;
    private Color _textColor = Color.white;
    private UIElement _owner = null;
    private boolean _disabled = false;
    
    public MenuItem(String text)
    {
        this(text, null);
    }
    
    public MenuItem(String text, Image iconImg)
    {
        _text = text;
        _iconImage = iconImg;
    }
    
    public Image getIconImage()
    {
        return _iconImage;
    }

    public void setIconImage(Image iconImg)
    {
        _iconImage = iconImg;
    }

    public String getText()
    {
        return _text;
    }

    public void setText(String text)
    {
        _text = text;
    }

    public Color getTextColor()
    {
        return _textColor;
    }

    public void setTextColor(Color textColor)
    {
        _textColor = textColor;
    }

    public int getId()
    {
        return _id;
    }

    public void setId(int id)
    {
        _id = id;
    }

    public Object getReferencedObject()
    {
        return _referencedObject;
    }

    public void setReferencedObject(Object representedObject)
    {
        _referencedObject = representedObject;
    }

    public String getTooltipText()
    {
        return _tooltip;
    }

    public void setTooltipText(String tooltip)
    {
        _tooltip = tooltip;
    }

    public UIElement getOwnerComponent()
    {
        return _owner ;
    }

    public void setOwnerComponent(UIElement owner)
    {
        _owner = owner;
    }

    public String getShortcutString()
    {
        return _shortcutString;
    }

    public void setShortcutString(String shortcutString)
    {
        _shortcutString = shortcutString;
    }

    /**
     * Checks for equality only the referenced object and id of this MenuItem,
     * not the representation. MenuItems with equal referenced object and same
     * id are treated as equal, even if they show different text or icons.
     */
    public boolean equals(Object obj)
    {
        if (obj instanceof MenuItem) {
            MenuItem other = (MenuItem)obj;
            if (_referencedObject == null) {
                return other._id == _id;
            } else {
                return other._id == _id &&
                other._referencedObject.equals(_referencedObject); 

            }
        }
        return false;
    }

    public int hashCode()
    {
        int result = 17;
        result = 37*result + _id;
        if (_referencedObject != null) {
            result = 37*result + _referencedObject.hashCode(); 
        }
        return result;
    }

    protected Object clone() throws CloneNotSupportedException
    {
        return super.clone();
    }

    public boolean isDisabled()
    {
        return _disabled;
    }

    public void setDisabled(boolean disabled)
    {
        _disabled = disabled;
    }
    
    


}
